/*
 * @Author: Leo.wang wanglizhigs@163.com
 * @Date: 2025-09-08 20:26:25
 * @LastEditors: Leo.wang wanglizhigs@163.com
 * @LastEditTime: 2025-09-08 21:55:03
 * @FilePath: /medical-companion-manage/src/views/Hospital/schema.tsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { toRaw } from 'vue';
import { Table, Button, Space, Divider } from 'ant-design-vue';
import { uploadFile } from '@/api/common.api'
const { VITE_FILE_URL } = import.meta.env;
import { useInterfaceStore } from '@/store/modules/interface.store';
import { formatOptions } from '@/utils/format';


export const tableSchemas = [
  {
    title: '编号',
    dataIndex: 'id',
    key: 'id',
    align: 'center',
    width: 60,
  },
  {
    title: '医院名称',
    dataIndex: 'name',
    key: 'name',
    align: 'center',
    // inSearch: true,
    width: 200,
  },
  {
    title: '图标',
    dataIndex: 'icon',
    key: 'icon',
    align: 'center',
    width: 80,
    customRender({ text, record, index, column }) {
      return <a-image
        preview={false}
        width={50}
        height={50}

        src={`${VITE_FILE_URL}${text}`}
      />

    }
  },
  {
    title: '等级',
    dataIndex: 'level',
    key: 'level',
    align: 'center',
    // inSearch: true,
    width: 120,
    customRender({ text, record, index, column }) {
      return text.level;
    }
  },
  {
    title: '地址',
    dataIndex: 'address',
    key: 'address',
    align: 'center',
    width: 160,
    //  inSearch: true
  },
  {
    title: '简介',
    dataIndex: 'introduction',
    key: 'introduction',
    align: 'left',
  },

];



export function getFormSchemas() {
  
  const interfaceStore = useInterfaceStore();
  console.log("interfaceStore1", interfaceStore.hospitalLevelList)
  // const interfaceStore = {
  //   orderStatusList: []
  // }
  const formSchemas = [
    {
      component: 'Input',
      label: 'ID',
      name: 'id',
      dataIndex: 'id',
      vShow: false,
    },
    {
      component: 'Input',
      label: '医院名称',
      dataIndex: 'name',
      name: 'name',
    },
    {
      component: 'Upload',
      label: '图标',
      dataIndex: 'icon',
      name: 'icon',
      componentProps: {
        maxCount: 1,
        showUploadList: false,
        listType: "picture-card",

        bindCustomRequest(formState, { file }) {
          const formData = new FormData();
          formData.append('file', file);
          uploadFile(formData).then(({ path }) => {
            formState.icon = path
          })
        }
      }
    },
    {
      component: 'Select',
      label: '等级',
      dataIndex: 'levelId',
      name: 'levelId',
      componentProps: {
        options: formatOptions(toRaw(interfaceStore.hospitalLevelList), { hasAll: true, label: 'level' })
      }
    },
    {
      component: 'InputTextArea',
      label: '地址',
      dataIndex: 'address',
      name: 'address',
    },
    {
      component: 'InputTextArea',
      label: '简介',
      dataIndex: 'introduction',
      name: 'introduction',
    },

  ];


  return formSchemas
}
